package com.xbongbong.saas.enums.business;

import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import lombok.Getter;


/**
 * 枚举
 *
 * @author jyh
 * @version v1.0
 * @date 2020/12/21 10:31
 * @since v1.0
 */
@Getter
public enum MarketingBaseEnum {
    //营销公共枚举
    //券logo
    COUPON_LOGO("file_1", "券logo", "couponLogo", FieldTypeEnum.IMAGE.getType(), 1, 0, 1, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //品牌名称
    BRAND_NAME("text_1", "品牌名称", "brandName", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //活动名称
    NAME("text_2", "活动名称", "name", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //券金额
    AMOUNT("num_1", "券面额", "amount", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //发售数量类型  0不限制 1自定义
    COUPON_NUM_TYPE("text_3", "发售数量类型", "couponNumType", FieldTypeEnum.COMBO_NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //发券数量
    NUM("num_2", "发券数量", "number", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //活动类型
    TYPE("text_15", "活动类型", "type", FieldTypeEnum.COMBO_NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //活动时间
    ACTIVITY_TIME("text_10", "活动时间", "activityTime", FieldTypeEnum.TEXT.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //适用地区
    APPLICABLE_LOCATION("array_2","适用地区","applicableLocation",  FieldTypeEnum.APPLICATION_AREA.getType(),1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //适用对象类型
    APPLICABLE_OBJECT_TYPE("text_5", "适用对象类型", "applicableObjectType", FieldTypeEnum.COMBO_NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //适用对象
    APPLICABLE_OBJECT("text_12", "适用对象", "applicableObjectType", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //领取数量
    GET_NUM("num_9", "领取数量", "getNum", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //核销数量
    USED_NUM("num_10", "核销数量", "usedNum", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //核销率
    WRITE_OFF_RATE("text_11", "核销率", "writeOffRate", FieldTypeEnum.TEXT.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //状态 0上架，1下架，2待上架
    STATUS("num_11", "状态", "status", FieldTypeEnum.COMBO_NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //创建人
    CREATOR_ID("creatorId", "创建人", "creatorId", FieldTypeEnum.CREATORID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9670, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //创建时间
    ADD_TIME("addTime", "创建时间", "addTime", FieldTypeEnum.ADDTIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9740, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //更新时间
    UPDATE_TIME("updateTime", "更新时间", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9730, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //活动开始时间
    BEGIN_TIME("date_1", "活动开始时间", "beginTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 0, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //活动结束时间
    END_TIME("date_2", "活动结束时间", "endTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 0, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //不适用商品类型
    INAPPLICABLE_PRODUCT_TYPE("text_7", "不适用商品类型", "inapplicableProductType", FieldTypeEnum.COMBO_NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //适用具体经销商
    DISTRIBUTOR("array_4","适用具体经销商","applicableLocation",  FieldTypeEnum.CHECKBOX_GROUP.getType(),1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //不适用商品
    INAPPLICABLE_PRODUCT("array_5","不适用商品","disableProduct",  FieldTypeEnum.SELECT_PRODUCT.getType(),1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //适用商品
    APPLICABLE_PRODUCT("array_6","适用商品","disableProduct",  FieldTypeEnum.SELECT_PRODUCT.getType(),1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //适用经销商级别
    DISTRIBUTOR_LEVEL("array_3","适用经销商级别","distributorLevel",  FieldTypeEnum.COMBO_CHECK.getType(),1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //投放渠道
    LAUNCH_CHANNEL("array_1","投放渠道","launchChannel",  FieldTypeEnum.CHECKBOX_GROUP.getType(),1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //投放门槛
    LAUNCH_THRESHOLD("num_3", "投放门槛", "launchThreshold", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //使用须知
    INSTRUCTION("text_4", "使用须知", "instruction", FieldTypeEnum.RICH_TEXT_EDITOR.getType(), 3, 0, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //券有效期类型 0相对日期，1固定日期
    VALIDITY_TYPE("text_6", "券有效期类型", "validityType", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //券有效期置（）日期  具体日期
    VALIDITY_TIME("date_3", "券有效期置", "validityTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //领取后...天内有效  相对日期
    VALIDITY_DAYS("num_4", "领取多少天有效", "validityDays", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //领取后...天内不可用  相对日期
    FORBID_DAYS("num_5", "领取多少天内不可用", "forbidDays", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //是否支持重复领取 0支持，1不支持
    ENABLE_REPEAT_GET("text_8", "是否支持重复领取", "enableRepeatGet", FieldTypeEnum.RADIO_GROUP.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //每人每日最多领取
    DAILY_LIMIT_NUMBER("num_6", "每人每日最多领取", "dailyLimitNumber", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //每人最多领取
    LIMIT_NUMBER("num_7", "每人最多领取", "LimitNumber", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //满多少使用
    FULL_REDUCTION_AMOUNT("num_8", "满多少使用", "LimitNumber", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //指令投放码
    HASH_CODE("text_9", "指令投放码", "hashCode", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //活动优先级
    PRIORITY("num_12", "优先级", "priority", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),

    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    MarketingBaseEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                      Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 对data内的字段拼上“data.”
     *
     * @author jyh
     * @version v1.0
     * @date 2020/12/21 10:31
     * @since v1.0
     */
    public static String getAttrConnectData(MarketingBaseEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * 获取es查询、聚合字段
     * data在库内是json对象，对data字段内某个key做es【精确查询】时，需要在其前拼上“data.”，且【text等类型的】要在后面拼“.keyword”
     *
     * @param cache 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author jyh
     * @version v1.0
     * @date 2020/12/21 10:31
     * @since v1.0
     */
    public static String getEsAttr4Keyword(MarketingBaseEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

}
